package upcweb.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import upcweb.modelo.ClsUsuario;

public class CheckLogin {

	public ClsUsuario getSession(HttpServletRequest request,
			HttpServletResponse response){
		if (request.getSession().getAttribute("sesion")==null){		
			return null;
		}
		else {
			return (ClsUsuario)request.getSession().getAttribute("sesion");
		}
	}
	
	public boolean isSession(HttpServletRequest request,
			HttpServletResponse response){
		return (getSession(request, response)==null?false:true);
	}
	
	public void setSesion(HttpServletRequest request, ClsUsuario user){
		try {
			request.getSession().setAttribute("sesion", user);
		} catch (Exception e) {
			// TODO: handle exception
			System.err.println(e.getMessage());
		}
	}
	
	public void closeSesion(HttpServletRequest request){
		try {
			request.getSession().setAttribute("sesion", null);
		} catch (Exception e) {
			// TODO: handle exception
			System.err.println(e.getMessage());
		}
	}
	
}
